home *** CD-ROM | disk | FTP | other *** search
- 'NumParsCmds - Returns the numer of parameters on command line
-
- FUNCTION NumParsCmds%(Cmd$) PUBLIC
- StrLen% = LEN(cmd$)
- FOR I% = 1 TO StrLen%
- Temp$ = MID$(Cmd$,i%,1)
- IF (Temp$ <> " " AND Temp$ <> CHR$(9) AND Temp$ <> "/" AND Temp$<>"-") THEN
- IF NOT Included% THEN
- INCR NumArgs%
- Included% = -1
- END IF
- ELSE
- Included% = 0
- END IF
- NEXT I%
- NumParsCmds%=NumArgs%
- END FUNCTION
-
- 'ParseCmds - does actual parsing of command line
-
- SUB ParseCmds(Cmd$,Args$()) PUBLIC
- StrLen% = LEN(cmd$)
- FOR I% = 1 TO StrLen%
- Temp$ = MID$(Cmd$,i%,1)
- IF (Temp$ <> " " AND Temp$ <> CHR$(9) AND_
- Temp$ <> "/" AND Temp$<>"-") THEN
- IF NOT Included% THEN
- NumArgs% = NumArgs% + 1
- Included% = -1
- END IF
- Args$(NumArgs%) = Args$(NumArgs%) + Temp$
- ELSE
- Included% = 0
- END IF
- NEXT I%
- END SUB
-
- ' Main Demo
- Numargs%=NumParsCmds%(COMMAND$)
- DIM Args$(1:Numargs%)
- CALL ParseCmds(COMMAND$,Args$())
-
- PRINT "There are";numargs%;"commands on the command line"
- FOR i%= 1 TO numargs%
- PRINT "Argument number";i%;" is: ";args$(i%)
- NEXT
- END
-
- ' This code is based on an example from Berry Erick which was based on
- ' and example from Henry Piper.